<?php
require_once("../common/config.php");
$conn = new connectDb();

$basic_id = $_POST['basic_id'];
$userIp = $_POST['userIp'];
$type = $_POST['type'];


$sql = "SELECT * FROM `food_vote` WHERE basic_id = $basic_id and ip = '$userIp'";
$query = mysql_query($sql) or die (mysql_error());
$num  = mysql_num_rows($query);

if($num == 0)
{
	if($type == 1)
	{
		$query_good = mysql_query("insert into `food_vote` (`id`,`ip`,`basic_id`,`good`,`create_time`) values (null,'$userIp','$basic_id','$type',now())") or die (mysql_error());
	}else
	{
		$query_bad = mysql_query("insert into `food_vote` (id,ip,basic_id,bad,create_time) values (null,'$userIp','$basic_id','$type',now())") or die (mysql_error());
	}
}

$sql_total = "SELECT * FROM `food_vote` WHERE basic_id = '$basic_id'";
$query_total = mysql_query($sql_total) or die (mysql_error());
$num_total = mysql_num_rows($query_total);

$sql_num_good = "SELECT * FROM `food_vote` WHERE basic_id = '$basic_id' and good = 1";
$query_num_good = mysql_query($sql_num_good) or die (mysql_error());
$num_good = mysql_num_rows($query_num_good);

$scoreRate = $num_good/$num_total;
echo round($scoreRate,1);
	

?>